<%= page_title "Edit #{@project.name} Kubernetes Resources" %>

<section>
  <%= form_tag update_many_project_kubernetes_deploy_group_roles_path(@project), method: :put, class: "form-horizontal" do %>
    <% rows = [
        [:delete_resource, "Delete resource", :boolean],
        [:replicas, "Replicas"],
        [:requests_cpu, 'Requests CPU Cores'],
        [:requests_memory, 'Requests Memory in MB'],
        [:limits_cpu, 'Limits CPU Cores'],
        [:limits_memory, 'Limits Memory in MB']
    ] %>
    <table class="table table-hover table-condensed">
      <thead>
        <tr>
          <th>Deploy Group</th>
          <th>Role</th>
          <% rows.each do |_, label| %>
            <th><%= label %></th>
          <% end %>
        </tr>
      </thead>

      <% @deploy_group_roles.each do |deploy_group_role| %>
        <% if deploy_group_role.errors.any? %>
          <tr>
            <td colspan="<%= 2 + rows.size %>"><%= render 'shared/errors', object: deploy_group_role %></td>
          </tr>
        <% end %>
        <tr>
          <td><%= deploy_group_role.deploy_group.name %></td>
          <td><%= deploy_group_role.kubernetes_role.name %></td>
          <%= fields_for "kubernetes_deploy_group_roles[#{deploy_group_role.id}]", deploy_group_role do |field| %>
            <% rows.each do |attribute, _, type| %>
              <td>
                <% if type == :boolean %>
                  <%= field.check_box attribute %>
                <% else %>
                  <%= field.text_field attribute, size: 10 %>
                <% end %>
              </td>
            <% end %>
          <% end %>
        </tr>
      <% end %>
    </table>

    <%= submit_tag "Update all" %>
  <% end %>
</section>
